<?php
namespace Attendance\Controller;
use Common\Controller\AdminbaseController;
use Home\Service\AccountService;
// +----------------------------------------------------------------------
// | Date:2017年3月6日
// +----------------------------------------------------------------------
// | Author: EK_熊<1439527494@qq.com>
// +----------------------------------------------------------------------
// | Description: 此文件作用于****
// +----------------------------------------------------------------------
class ScheduleController extends AdminbaseController{
    protected  $type;
    public function _initialize(){
        parent::_initialize();
        $this->model = D('Schedule');
        $this->type = C('SCHEDULE_TYPE');
        $this->assign('type',$this->type);
        
    }
    
    public function index(){

        $this->_index_data();
        $this->display();
    }
    
    public function index_print(){
/*         $mon = get_month_range();
        for ($day=$mon['start'];$day <= $mon['end'];$day=date('Y-m-d',strtotime("$day +1 day"))){
            if (!is_work_day($day)) continue;
            $timeStmp = strtotime($day);

            $week = date('w',$timeStmp);
            $daybox[$day]['week'] = get_week($timeStmp);
            $daybox[$day]['date'] = date('d',$timeStmp);
            
            
        }       
        
        $start = I('start_time');
        $end = I('end_time');
        $list = $this->model->admin_showlist($start,$end);//获取全月的起止时间
        
        $this->assign('list',$list);
        $this->assign('daybox',$daybox);
*/ 
        
        $this->_index_data();
        $timestamp = time();
        
        $this->show_print('index',"高管行程$timestamp");
    }
    
    private function _index_data(){
        $start = I('start_time');
        $end = I('end_time');
        $weekCn = ['周一','周二','周三','周四','周五','周六','周日'];
        $map = json_decode(urldecode(I('map')),true);
        
        if ($map){
            $start = $map['start'];
            $end = $map['end'];
        }
        if (empty($start) && empty($end)) {
            $currentmon = get_week_range();
            $start = $currentmon['start'];
            $end = $currentmon['end'];
        }else{
            $where['start'] =$start; 
            $where['end'] =$end; 
            $this->assign('map',urlencode(json_encode($where)));
        }
        for($day = $start;$day<=$end;$day = date('Y-m-d',strtotime("$day +1 day"))){
            $w = date('w',strtotime("$day -1 day"));
            $w_cn =$weekCn[$w];
            $newWeek[$day] = $w_cn;
        }
        $list = $this->model->admin_showlist($start,$end);
        $this->assign('list',$list);
        $this->assign('newweek',$newWeek);
    }
    
    /**
     * 配置页面
     * 
     * date:2017年7月24日
     * author: EK_熊
     */
    public function config(){
        $account = new AccountService();
        $namelist = $account->get_schedule_list();//获取特权是4的数据
        $key = 'schedule_top';
        $toplist = F($key);
        if ($toplist) {
            
            foreach ($namelist as $k =>$v) {
                $namelist[$k]['top'] = 0;
                if (in_array($v['sn'],$toplist)){
                    $namelist[$k]['top'] = 1;
                }
            }
        }
        $this->assign('namelist',$namelist);
        $this->display();
    }
    
    /**
     * 设置置顶
     * 
     * date:2017年7月24日
     * author: EK_熊
     */
    public function top(){
        $sn = I('sn');
        $status = I('status');
        $key = 'schedule_top';
        $toplist = F($key);
        
        if ($status == 1) {
            
            if (!$toplist) {
                $toplist = [];
            }
//             $toplist[] = $sn;
            array_unshift($toplist,$sn);
        }else{
            $idxToplist=array_search($sn ,$toplist);
            array_splice($toplist,$idxToplist,1);
        }
        
       F($key,$toplist);
        $this->success('设置成功！');
    }
    
}